package anthology.daily_question._24_10;
//https://leetcode.cn/problems/minimum-operations-to-make-binary-array-elements-equal-to-one-ii/?envType=daily-question&envId=2024-11-08
public class _3192使二进制数组全部等于1的最少操作次数2 {
    class Solution {
        public int minOperations(int[] nums) {
            int operation = 0;
            for (int num : nums) {
                if (num == (operation % 2)) {
                    operation++;
                }
            }
            return operation;
        }
    }
    class Solution2 {
        public int minOperations(int[] nums) {
            int operation = 0;
            for (int i = nums.length - 2; i >= 0; i--) {
                if (nums[i] != nums[i + 1]) {
                    operation++;
                }
            }
            return nums[0] == 1 ? operation : operation + 1;
        }
    }

}
